package p19_动态通知调用;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Config {
    @Aspect
    static class MyAspect {
        //这是静态通知
        @Before("execution(* foo(..))")
        public void before() {
            System.out.println("前置...");
        }
        //这是动态通知，可以在通知里获取传给目标方法的参数
        @After("execution(* foo(..)) && args(x)")
        public void after(int x) {
            System.out.println("后置... -> " + x);
        }
    }
    static class Target {
        public void foo(int x) {
            System.out.println("目标方法 -> " + x);
        }
    }

    @Bean
    public MyAspect myAspect() {
        return new MyAspect();
    }

    @Bean
    public Target target() {
        return new Target();
    }


}
